package jmu.cyxwcy.librarymanagement.controller;


import jmu.cyxwcy.librarymanagement.pojo.Classes;
import jmu.cyxwcy.librarymanagement.pojo.College;
import jmu.cyxwcy.librarymanagement.pojo.Major;
import jmu.cyxwcy.librarymanagement.pojo.Result;
import jmu.cyxwcy.librarymanagement.service.IClassesService;
import jmu.cyxwcy.librarymanagement.service.IMajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-06-26
 */
@RestController
@RequestMapping("/classes")
//班级
public class ClassesController {
    @Autowired
    private IClassesService iClassesService;

    @PostMapping("/add")
    public Result add(@RequestBody Classes classes){
        iClassesService.getBaseMapper().insert(classes);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Classes classes){
        iClassesService.updateById(classes);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(Integer classId){
        iClassesService.removeById(classId);
        return Result.success();
    }
    @GetMapping("/findbymajorid")
    public Result findByMajorId(@RequestParam Integer majorId) {
        List<Classes> classes = iClassesService.findByMajorId(majorId);
        return Result.success(classes);
    }

    @GetMapping("/findbyclassnamepartial")
    public Result findClassesByPartialClassName(@RequestParam String classNamePartial) {
        List<Classes> classes =  iClassesService.findByCollegeNamPartial(classNamePartial);
        return Result.success(classes);
    }

    @GetMapping("/findbymajorname")
    public Result findByMajorName(@RequestParam String majorName, @RequestParam String classNamePartial) {
        List<Classes> classes = iClassesService.findByMajorName(majorName, classNamePartial);
        return Result.success(classes);
    }
}
